package kr.kosta.mvc;

import javax.validation.Valid;

import kr.kosta.mvc.model.Member;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@RequestMapping(value="member")
@Controller
public class MemberController
{
	@RequestMapping(value="form.do", method=RequestMethod.GET)
	public String form(Model model)
	{
		System.out.println("[ member form ]");
		
		model.addAttribute("member", new Member());
		
		return "member/form";
	}

	@RequestMapping(value="regist.do", method=RequestMethod.POST)
	public String regist(@ModelAttribute @Valid Member member, BindingResult result)
	{
		System.out.println("member regist");
		
		System.out.println("id : " + member.getId());
		System.out.println("firstName : " + member.getFirstName());
		System.out.println("lastName : " + member.getLastName());
		System.out.println("phone : " + member.getPhone());
		System.out.println("city : " + member.getCity());
		
		if(result.hasErrors())
		{
			System.out.println("member has errors");
		}
		
		return "member/form";
	}
}
